package net.lab0.nebula.gui;

import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JProgressBar;
import java.awt.Insets;
import javax.swing.JButton;

public class StatusBar
extends JPanel
{
    private JLabel       lblStatus;
    private JProgressBar progressBar;
    
    public StatusBar()
    {
        GridBagLayout gridBagLayout = new GridBagLayout();
        gridBagLayout.columnWidths = new int[] { 0, 0, 0, 0 };
        gridBagLayout.rowHeights = new int[] { 0, 0 };
        gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE };
        gridBagLayout.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
        setLayout(gridBagLayout);
        
        lblStatus = new JLabel("Status");
        GridBagConstraints gbc_lblStatus = new GridBagConstraints();
        gbc_lblStatus.insets = new Insets(0, 0, 0, 5);
        gbc_lblStatus.gridx = 0;
        gbc_lblStatus.gridy = 0;
        add(lblStatus, gbc_lblStatus);
        
        progressBar = new JProgressBar();
        progressBar.setStringPainted(true);
        progressBar.setMaximum(1000);
        GridBagConstraints gbc_progressBar = new GridBagConstraints();
        gbc_progressBar.fill = GridBagConstraints.HORIZONTAL;
        gbc_progressBar.insets = new Insets(0, 0, 0, 5);
        gbc_progressBar.gridx = 1;
        gbc_progressBar.gridy = 0;
        add(progressBar, gbc_progressBar);
        
        JButton btnLog = new JButton("Log");
        btnLog.setEnabled(false);
        GridBagConstraints gbc_btnLog = new GridBagConstraints();
        gbc_btnLog.gridx = 2;
        gbc_btnLog.gridy = 0;
        add(btnLog, gbc_btnLog);
    }
    
    public void setText(String statusName, String description)
    {
        lblStatus.setText(statusName);
        if (description != null)
        {
            lblStatus.setToolTipText(description);
        }
        else
        {
            lblStatus.setToolTipText("");
        }
    }
    
    public void setProgress(float progress)
    {
        progressBar.setValue((int) (progress * 1000));
    }
    
}
